import VueRouter from "vue-router";
import Vue from "vue";
import store from "./store";

import Home from "../pages/index/Index";
import Login from "../pages/login/Login";
import Signup from "../pages/login/Signup";
import UserShare from "../pages/user/Share";
import UserInvite from "../pages/user/Invite";
import UserAbout from "../pages/user/About";
import UserAccount from "../pages/user/Account";
import UserQa from "../pages/user/Qa";
import UserLoan from "../pages/user/Loan";
import UserLoanDetail from "../pages/user/LoanDetail";
import UserLoanComment from "../pages/user/LoanComment";
import UserLogMoney from "../pages/user/LogMoney";
import UserLogTicket from "../pages/user/LogTicket";
import UserKyc from "../pages/user/Kyc";
import UserWithdraw from "../pages/user/Withdraw";
import UserDeposit from "../pages/user/Deposit";
import UserLogWithdraw from "../pages/user/LogWithdraw";
import Loan from "../pages/loan/Index";
import LoanDetail from "../pages/loan/Detail";
import Chat from "../pages/chat/Chat";
import Web from "../pages/web/web.vue";

import Cd from "../pages/h5/cd.vue";



import UserText from "../pages/user/Text";
import Wechart from "../pages/user/Wechart";
import Sqb from "../pages/user/Sqb.vue";

Vue.use(VueRouter);

const routes = [
    {
        path: "/web",
        component: Web,
        name: "web",
        meta: {
            hideBottomNav: true // 标记该页面需要隐藏底部栏
        }
    },
    {
        path: "/h5/cd",
        component: Cd,
        name: "cd",
        meta: {
            hideBottomNav: true // 标记该页面需要隐藏底部栏
        }
    },

    {
        path: "/",
        component: Home,
        name: "home",
    },
    {
        path: "/loan",
        component: Loan,
        name: "loan",
    },
    {
        path: "/loan/:id",
        component: LoanDetail,
        name: "loan-detail",
    },
    {
        path: "/login",
        component: Login,
        name: "login",
        meta: {
            layout: "fullpage",
        }
    },
    {
        path: "/signup",
        component: Signup,
        name: "signup",
        meta: {
            layout: "fullpage",
        }
    },
    {
        path: "/user",
        component: UserAccount,
        name: "user-account",
    },
    {
        path: "/user/share",
        component: UserShare,
        name: "user-share",
    },
    {
        path: "/user/invite",
        component: UserInvite,
        name: "user-invite",
    },
    {
        path: "/user/about",
        component: UserAbout,
        name: "user-about",
    },
    {
        path: "/user/qa",
        component: UserQa,
        name: "user-qa",
    },
    {
        path: "/user/kyc",
        component: UserKyc,
        name: "user-kyc",
    },
    {
        path: "/user/withdraw",
        component: UserWithdraw,
        name: "user-withdraw",
    },
    {
        path: "/user/text",
        component: UserText,
        name: "user-text",
    },
    {
        path: "/user/wechart",
        component: Wechart,
        name: "user-wechart",
    },
    {
        path: "/user/sqb",
        component: Sqb,
        name: "user-sqb",
    },
    {
        path: "/user/deposit",
        component: UserDeposit,
        name: "user-deposit",
    },
    {
        path: "/user/log/withdraw",
        component: UserLogWithdraw,
        name: "user-log-withdraw",
    },
    {
        path: "/user/log/money",
        component: UserLogMoney,
        name: "user-log-money",
    },
    {
        path: "/user/log/ticket",
        component: UserLogTicket,
        name: "user-log-ticket",
    },
    {
        path: "/user/loan",
        component: UserLoan,
        name: "user-loan",
    },
    {
        path: "/user/loan/:id",
        component: UserLoanDetail,
        name: "user-loan-detail",
    },
    {
        path: "/user/loan/:id/comment",
        component: UserLoanComment,
        name: "user-loan-comment",
    },
    {
        path: "/user/chat",
        component: Chat,
        name: "user-chat",
        meta: {
            layout: "fullpage",
        }
    },



];

const router = new VueRouter({
    mode: 'hash',
    routes,
    /* eslint-disable no-unused-vars */
    scrollBehavior(to, from, savedPosition) {
        // return 期望滚动到哪个的位置
        if (savedPosition) {
            return savedPosition;
        } else {
            return { x: 0, y: 0 };
        }
    }
});

/* eslint-disable no-unused-vars */
router.beforeEach((to, from, next) => {
    next();
});


/* eslint-disable no-unused-vars */
router.afterEach((to, from) => {
    if (to.meta && typeof to.meta.layout !== 'undefined') {
        store.commit("layout", to.meta.layout);
    } else {
        store.commit("layout", "default");
    }
})


export default router;
